package com.guohui.feign1.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.guohui.feign1.client.Boot1FeignClient;
import com.guohui.feign1.service.HelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service("helloService")
@SuppressWarnings("unused")
public class HelloServiceImpl implements HelloService{

  private Logger logger = LoggerFactory.getLogger(getClass());
  
  @Value("${spring.application.name}")
  private String serviceName;
  
  @Autowired
  Boot1FeignClient boot1FeignClient;
  
  @Override
  @HystrixCommand(fallbackMethod = "sayHelloFallback")
  public String sayHello(String client) {
    String success = boot1FeignClient.hello(serviceName);
    return success;
  }

  private String sayHelloFallback(String client) {
    logger.debug(client + " invoke boot1 failed");
    return "Failure";
  }
}
